package com.dhcc.bpm.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.system.entity.DataTable;
import com.dhcc.bpm.modules.system.entity.DataTableColumn;
import com.dhcc.bpm.modules.system.service.IDataDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName DataDictController
 * @Description 数据字典控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/datadict")
@Api(value = "数据字典", tags = "数据字典")
public class DataDictController extends BladeController {
	private static final Logger log = LoggerFactory.getLogger(DataDictController.class);
    @Autowired
	private IDataDictService dataDictService;

	/**
	 * @Description 详情
	 * @Author sjm
	 * @Date 10:02 2020/2/22 0022
	 * @param tableName
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.system.vo.DataTableColumn>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入dict")
	@ApiLog("字典详情")
	@Log(title = "字典详情", businessType = BusinessType.SELECT)
	public R<IPage<DataTableColumn>> detail(@Valid @Param("tableName") String tableName, Query query) {
		IPage<DataTableColumn> detail = dataDictService.selectDataTableColumnByTableName(Condition.getPage(query), tableName);
		return R.data(detail);
	}

	/**
	 * @Description 列表
	 * @Author sjm
	 * @Date 10:02 2020/2/22 0022
	 * @param dataTable
	 * @return org.springblade.core.tool.api.R<java.util.List<org.springblade.core.tool.node.INode>>
	 **/
	@RequestMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "列表", notes = "传入dict")
	@ApiLog("字典列表")
	@Log(title = "字典列表", businessType = BusinessType.SELECT)
	public R<IPage<DataTable>> list(DataTable dataTable, Query query) {
		IPage<DataTable> list = dataDictService.selectDataTablePage(Condition.getPage(query), dataTable);
		return R.data(list);
	}

}
